IB_DEFAULT_PAGE = 'C:\\'

import clr
from System.Collections import *
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import *
clr.AddReferenceToFile("External.dll")
import External

class IronBrowser(Form, External.Py):
	def __init__(self):
		self.Text = 'IronBrowser - The dangerouse exploration'
		self.Width = 800
		self.Height = 600

		self.address = TextBox()
		self.address.Dock = DockStyle.Top
		self.address.KeyPress += self.OnKeyPress
		self.Controls.Add(self.address)
		
		self.browser = WebBrowser()
		self.browser.Dock = DockStyle.Fill
		self.browser.Navigated += self.OnNavigated
		self.browser.ObjectForScripting = self
		self.Controls.Add(self.browser)
		
		self.browser.Navigate(IB_DEFAULT_PAGE)

	def py(self, script, scriptInput):
		scriptOutput = None
		exec script
		return scriptOutput
				
	def OnKeyPress(self, sender, args):
		if args.KeyChar == u'\r':
			self.browser.Navigate(self.address.Text.strip())        

	def OnNavigated(self, sender, args):
		self.address.Text = args.Url.ToString()
		
Application.Run(IronBrowser())
